# 超时
class WordDictionary:

    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.wordSet = set()
        self.wordList = []

    def addWord(self, word: str) -> None:
        """
        Adds a word into the data structure.
        """
        self.wordSet.add(word)
        self.wordList.append(word)

    def search(self, word: str) -> bool:
        """
        Returns if the word is in the data structure. A word could contain the dot character '.' to represent any one letter.
        """
        if word in self.wordSet:
            return True

        for it in self.wordList:
            if self.match(it, word):
                return True
        return False

    def match(self, word: str, patt: str):
        if len(word) != len(patt):
            return False

        for index, letter in enumerate(patt):
            if letter == '.':
                continue
            if letter != word[index]:
                return False
        return True



# Your WordDictionary object will be instantiated and called as such:
obj = WordDictionary()
obj.addWord("bad")
obj.addWord("dad")
obj.addWord("mad")
print(obj.search("pad")) # false
print(obj.search("bad")) # true
print(obj.search(".ad")) # true
print(obj.search("b..")) # true